package com.ssb.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.exception.BusinessException;
import com.apache.ius.plugin.CustomMethodPlugin;
import com.apache.tools.StrUtil;
import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;


/**
 * 创建的测试插件
 * @Author IUS platform administrators create generation
 * @Date 2020-1-31 13:51:04
 */
public class BrokerDetailPluginImpl extends HheSuperPlugin implements CustomMethodPlugin {
	private Logger log = Logger.getLogger(getClass());

	@Override
	public Object beforeInvoke(Map<String, Object> param) {
		log.info("start->> 执行插件事前方法....");

		//校验参数  当前登录人的USERID  USERENAME
		String userId = String.valueOf(param.get("uctUser.w_userId"));//渠道商ID
		log.info("userId-->"+userId);
		if(StrUtil.isNull(userId)){
			throw new BusinessException("渠道商userId不能为空");
		}
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT a.user_id,a.user_cname,b.father_id,b.premium,b.com_scale,b.amount,b.create_time,b.policy_no FROM ");
		sb.append(" (SELECT user_id,user_cname,policy_no FROM ss_commission_detail");
		sb.append(" WHERE org_id='"+userId+"') a");
		sb.append(" LEFT JOIN");
		sb.append(" (SELECT user_id father_id,premium,com_scale,amount,create_time,policy_no FROM ss_commission_detail");
		sb.append(" WHERE org_id='0' AND user_id='"+userId+"') b");
		sb.append(" ON a.policy_no = b.policy_no");
		List list = select(sb.toString(),DATA_SOURCE);
		log.info("ss_commission_detail_orgId_list-->"+list.toString());
		param.put(CustomMethodPlugin.pluginInnerReturn,list);
		param.put(CustomMethodPlugin.resultMark, "T");
		return param;
	}

	@Override
	public Object doInvoke(Map<String, Object> param) {
		log.info("start->> 执行插件方法....");

		return null;
	}

	@Override
	public Object afterInvoke(Map<String, Object> param) {
		log.info("start->> 执行插件事后方法....");

		return null;
	}

	/**
	 * 规则校验统一入口
	 * @param paramsVo
	 */
	public void run(ParamsVo paramsVo) {
		beforeInvoke(paramsVo.getParams());
	}


}

